package com.xuetang9.t9.hotel.controller;

import com.xuetang9.t9.hotel.beans.RoomState;
import com.xuetang9.t9.hotel.beans.RoomType;
import com.xuetang9.t9.hotel.services.IRoomStateService;
import com.xuetang9.t9.hotel.utils.HttpCodeEnum;
import com.xuetang9.t9.hotel.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 房间状态controller
 */
@Controller
@RequestMapping("/state")
@ResponseBody
public class RoomStateController {

    @Autowired
    private IRoomStateService roomStateService;


    /**
     * 房间状态总览
     * @return
     */
    @RequestMapping("/show")
    private ResponseResult stateShowList(){
        return roomStateService.findByAll();
    }


    /**
     * 房间状态总览
     * @return
     */
    @RequestMapping("/showstate")
    private ResponseResult stateShowStateList(){
        return roomStateService.findByStateAll();
    }

    /**
     * 房间状态保存
     * @param
     * @return
     */
    @RequestMapping(value = "/save",method = RequestMethod.POST)
    private ResponseResult save(@RequestBody RoomState roomState){
        if(roomState == null){
            return ResponseResult.okResult(HttpCodeEnum.PARAM_INVALID.getCode(),HttpCodeEnum.PARAM_INVALID.getErrorMessage());
        }
        if(roomStateService.save(roomState)){
            return ResponseResult.okResult(HttpCodeEnum.SUCCESS.getCode(),HttpCodeEnum.SUCCESS.getErrorMessage());
        }
        return ResponseResult.okResult(HttpCodeEnum.SERVER_ERROR.getCode(),HttpCodeEnum.SERVER_ERROR.getErrorMessage());
    }

    /**
     * 房间状态修改
     * @param
     * @return
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    private ResponseResult update(@RequestBody RoomState roomState){
        if(roomState == null){
            return ResponseResult.okResult(HttpCodeEnum.PARAM_INVALID.getCode(),HttpCodeEnum.PARAM_INVALID.getErrorMessage());
        }
        if(roomStateService.alter(roomState)){
            return ResponseResult.okResult(HttpCodeEnum.SUCCESS.getCode(),HttpCodeEnum.SUCCESS.getErrorMessage());
        }
        return ResponseResult.okResult(HttpCodeEnum.SERVER_ERROR.getCode(),HttpCodeEnum.SERVER_ERROR.getErrorMessage());
    }

    /**
     * 房间状态删除
     * @param
     * @return
     */
    @RequestMapping(value = "/remove/{id}")
    private ResponseResult save(@PathVariable("id") Integer id){
        if(id == null){
            return ResponseResult.okResult(HttpCodeEnum.PARAM_INVALID.getCode(),HttpCodeEnum.PARAM_INVALID.getErrorMessage());
        }
        if(roomStateService.remove(id)){
            return ResponseResult.okResult(HttpCodeEnum.SUCCESS.getCode(),HttpCodeEnum.SUCCESS.getErrorMessage());
        }
        return ResponseResult.okResult(HttpCodeEnum.SERVER_ERROR.getCode(),HttpCodeEnum.SERVER_ERROR.getErrorMessage());
    }
}
